import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)

const store = new Vuex.Store({
    state: {
        token:uni.getStorageSync("token"),
        userinfo:{
            userId:1
        },
    },
    getters: {
        getUserInfo(state){
            return state.userinfo
        }
    },
    mutations: {
		setToken(state, token){
			state.token = token
			uni.setStorageSync("token",token)
		},
		setUserInfo(state, userinfo){
            state.userinfo = userinfo
		}
    },
    actions:{
        userInit({ commit }){
            const token = uni.getStorageSync("token")
            commit("setToken",token)
        },
        logout({ commit }){
            commit("setToken",{})
            commit("setUserInfo",{})
        }
    }

})
export default store
